# Contributor: Sean McAvoy <seanmcavoy@gmail.com>
# Maintainer: Sean McAvoy <seanmcavoy@gmail.com>
pkgname=exabgp
pkgver=4.2.21
pkgrel=5
pkgdesc="BGP swiss army knife of networking"
url="https://github.com/Exa-Networks/exabgp"
arch="noarch"
license="BSD-3-Clause"
depends="py3-six py3-parsing py3-bitstring"
makedepends="py3-setuptools py3-gpep517"
checkdepends="py3-pytest"
subpackages="$pkgname-doc $pkgname-openrc $pkgname-pyc"
pkgusers="exabgp"
pkggroups="exabgp"
source="exabgp-$pkgver.tar.gz::https://github.com/Exa-Networks/exabgp/archive/refs/tags/$pkgver.tar.gz
	exabgp.initd
	exabgp.confd

	unvendor.patch
	"

build() {
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

check() {
	python3 -m venv --clear --without-pip --system-site-packages .testenv
	gpep517 install-wheel --destdir .testenv --prefix '' .dist/*.whl
	.testenv/bin/python3 -m pytest
}

package() {
	gpep517 install-wheel --destdir "$pkgdir" \
		.dist/*.whl
	rm -rf "$pkgdir"/usr/etc
	install -Dm644 -t "$pkgdir"/etc/exabgp/ "$builddir"/etc/exabgp/*.conf
	install -Dm644 -t "$pkgdir"/etc/exabgp/ "$builddir"/etc/exabgp/*.run
	install -Dm644 -t "$pkgdir"/etc/exabgp/run "$builddir"/etc/exabgp/run/*
	install -Dm644 "$builddir"/doc/man/exabgp.1 "$pkgdir"/usr/share/man/man1/exabgp.1
	install -Dm644 "$builddir"/doc/man/exabgp.conf.5 "$pkgdir"/usr/share/man/man5/exabgp.conf.5
	install -Dm755 "$srcdir"/exabgp.initd "$pkgdir"/etc/init.d/exabgp
	install -Dm644 "$srcdir"/exabgp.confd "$pkgdir"/etc/conf.d/exabgp
	PYTHONPATH="$builddir"/build/lib "$pkgdir"/usr/bin/exabgp --fi | sed "s/nobody/$pkgusers/g" > "$pkgdir"/etc/exabgp/exabgp.env
}

sha512sums="
0efc7143191e8b557297e9329354c01e2418e0c4c45753941eba3a1f063e77d17a0efa7a14a3062764e45e709f0598f491c10e2c02e751590bb7c0943b61932b  exabgp-4.2.21.tar.gz
0a6ee4116632d1d869216804d6ace385238347a871cf243b29cf3a77ed04366395ef4fdc28e749daf8f28f048e6eb8fd80bc82e74ad1e5f80b782548d7746a34  exabgp.initd
32d54bfd02f13d75c5d544141a4e3569ae873ab1ea77cb697a4475f18329c5b4e15a59ab0345b77a20bdfbe60e8322eb373af1f8530f96d5be07f4fb69ccba80  exabgp.confd
3abce29e126ee7706cdd0d2c97593127c1184522b606353332f07872524514e119b884991d9439e0db6e892a69017bcc696f57f462416ea818bf8a8c4c3a0ca6  unvendor.patch
"
